package com.sxwl.auth.service;

import com.sxwl.auth.client.UserClient;
import com.sxwl.auth.config.JwtProperties;
import com.sxwl.common.utils.JwtUtils;
import com.sxwl.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author reading
 * @Description TODO
 * @Date 2020/4/5 15:19
 */
@Service
public class AuthService {
    @Autowired
    private UserClient userClient;
    @Autowired
    private JwtProperties jwtProperties;
    public String login(String email, String password) {
        //根据用户查询
        User user = userClient.queryUser(email, password);
        if(user==null){
            return null;
        }
        //jwt生成token
        try {
            return  JwtUtils.generateToken(user.getId(),user.getUsername(),jwtProperties.getExpire(),this.jwtProperties.getPrivateKey());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

}
